import axios from './axios'

export const fetchTableData = query => {
  return axios.request({
      url: '/table.json',
      method: 'get',
      params: query
  });
};

export const fetchDepartmentData = async (query) => {
  return axios.request({
    url: '/common/departments',
    method: 'get',
    params: query
});
}

export const fetchDaiyue = async (condition) => {
  return axios.request({
    url: '/common/daiyue/search',
    method: 'post',
    data:{
      condition:{
        status:'审批中',
        currentHandler: localStorage.getItem("ms_username")
      }
    }
}); 
}

export const fetchDaiban = async (condition) => {
  return axios.request({
    url: '/common/daiban/search',
    method: 'post',
    data:{
      condition:{
        status:'审批中',
        currentHandler: localStorage.getItem("ms_username")
      }
    }
}); 
}

export const fetchDaibanById = async (id) => {
  return axios.request({
    url: `/common/daiban/${id}`,
    method: 'get',
}); 
}

export const fetchDaiyueById = async (id) => {
  return axios.request({
    url: `/common/daiyue/${id}`,
    method: 'get',
}); 
}

export const addDaiban = async (condition) => {
  condition["status"] = '审批中';
  return axios.request({
    url: '/common/daiban/',
    method: 'post',
    data:{
      condition:condition
    }
}); 
}


export const fetchlackMaterial = async (condition) => {
  return axios.request({
    url: '/common/lackmaterial/search',
    method: 'post',
    data:{
      condition:condition
    }
}); 
}

export const fetchUser = async (condition) => {
  return axios.request({
    url: '/common/users/search',
    method: 'post',
    data:{
      condition:condition
    }
}); 
}

export const fetchMenus = async (condition) => {
  return axios.request({
    url: '/common/menus/search',
    method: 'post',
    data:{
      condition:condition
    }
}); 
}

export const fetchRole = async (condition) => {
  return axios.request({
    url: '/common/roles/search',
    method: 'post',
    data:{
      condition:condition
    }
}); 
}


export const fetchProducts = async (condition) => {
  return axios.request({
    url: '/common/productStock/search',
    method: 'post',
    data:{
      condition:condition
    }
}); 
}


export const fetchItemTypes = async (condition) => {
  return axios.request({
    url: '/common/mms_item_types/search',
    method: 'post',
    data:{
      condition:condition
    }
}); 
}


export const fetchTransItemTypes = async (condition) => {
  return axios.request({
    url: '/common/item_types/search',
    method: 'post',
    data:{
      condition:condition
    }
}); 
}

export const fetchCurrentItemTypes = (typeCode) => {
  return axios.request({
    url: '/common/mms_item_types/search',
    method: 'post',
    data:{
      condition:{
        "ITEM_TYPE_CODE": typeCode
      }
    }
}); 
}

export const addWuyuanData = (condition) => {
  return axios.request({
    url: '/common/wuyuan/',
    method: 'post',
    data:{
      condition:condition
    }
}); 
}

export const fetchWuyuan = async (condition) => {
  return axios.request({
    url: '/common/wuyuan/search',
    method: 'post',
    data:{
      condition:condition
    }
}); 
}

export const fetchProcurementItems = async (condition) => {
  return axios.request({
    url: `/common/procurementItems/search`,
    method: 'post',
    data:{
      condition:condition
    }
}); 
}

export const addProcurementItems = (condition) => {
  return axios.request({
    url: `/common/procurementItems/`,
    method: 'post',
    data:{
      condition:condition
    }
}); 
}

export const fetchObj = async(collection, condition) => {
  return axios.request({
    url: `/common/${collection}/search`,
    method: 'post',
    data:{
      condition:condition
    }
  }); 
}

export const fetchObjSearch = async(condition) => {
  return axios.request({
    url: `/common/baozhangfukuan/search`,
    method: 'post',
    data:{
      condition:condition
    }
  }); 
}
export const fetchObjSave = async(condition) => {
  return axios.request({
    url: `/common/baozhangfukuan`,
    method: 'post',
    data:{
      condition:condition
    }
  }); 
}

export const fetchFundPlaySearch = async(condition) => {
  return axios.request({
    url: `/common/zijinjihua/search`,
    method: 'post',
    data:{
      condition:condition
    }
  }); 
}
export const fetchFundPlaySave = async(condition) => {
  return axios.request({
    url: `/common/zijinjihua`,
    method: 'post',
    data:{
      condition:condition
    }
  }); 
}

export const fetchApplicationSearch = async(condition) => {
  return axios.request({
    url: `/common/baozhangshenqing/search`,
    method: 'post',
    data:{
      condition:condition
    }
  }); 
}
export const fetchApplicationSave = async(condition) => {
  return axios.request({
    url: `/common/baozhangshenqing`,
    method: 'post',
    data:{
      condition:condition
    }
  }); 
}

export const addObj = (collection, condition) => {
  return axios.request({
    url: `/common/${collection}/`,
    method: 'post',
    data:{
      condition:condition
    }
}); 
}

export const fetchSupplierInfoSearch = async(condition) => {
  return axios.request({
    url: `/common/gongyingshang/search`,
    method: 'post',
    data:{
      condition: condition
    }
  }); 
}
export const addSupplierInfoSave = async(condition) => {
  return axios.request({
    url: `/common/gongyingshang`,
    method: 'post',
    data:{
      condition: condition
    }
  }); 
}


export const fetchAccountSearch = async(condition) => {
  return axios.request({
    url: `/common/gongyingshangzhanghao/search`,
    method: 'post',
    data:{
      condition: condition
    }
  }); 
}
export const addAccountSave = async(condition) => {
  return axios.request({
    url: `/common/gongyingshangzhanghao`,
    method: 'post',
    data:{
      condition: condition
    }
  }); 
}


export const fetchSupplierInfoSyncSearch = async(condition) => {
  return axios.request({
    url: `/common/supplierInfoSync/search`,
    method: 'post',
    data:{
      condition: condition
    }
  }); 
}